<?php
/**
 * Created by PhpStorm.
 * User: lzy 林子彦
 * Date: 2018/6/1
 * Time: 上午1:20
 */
namespace App\Admin\Repositories;
use App\Admin\Contracts\MenuInterface;
use App\Admin\Models\MenuModel;

/**
 * 后台菜单实现
 * Class DbMenuRepository
 * @package App\Admin\Repositories
 */
class DbMenuRepository implements MenuInterface{

    /**
     * @return MenuModel
     */
    public function getMenuModel(){
        return app()->make(MenuModel::class);
    }

    /**
     * 获取菜单条信息
     * @param $wheresaveMenuData
     * @return \Illuminate\Database\Eloquent\Model|mixed|null|object|static
     */
    public function getMenuList($where){
      return $this->getMenuModel()->newQuery()->where($where)->orderBy("sort","desc")->orderBy("id","asc")->get();
    }

    /**
     * 获取菜单单条信息
     * @param $where
     * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|mixed|null|object
     */
    public function getMenuInfo($where){
        return $this->getMenuModel()->newQuery()->where($where)->first();
    }
    /**
     * 保存菜单数据
     * @param $data
     * @return \Illuminate\Database\Eloquent\Model|mixed
     */
    public function saveMenuData($data){
        $data['hide']=empty($data["hide"])?0:1;
        $data['is_dev']=empty($data["is_dev"])?0:1;
        //$data=$this->getMenuModel()->filter($data); print_r($data);
        return $this->getMenuModel()->newQuery()->updateOrCreate(["id"=>$data["id"]],$data);
    }

    /**
     * 删除菜单
     * @param $data
     * @return mixed
     */
    public function delMenu($data){
        return $this->getMenuModel()->newQuery()->where(["id"=>$data["id"]])->delete();
    }


}
